<?php
class System_ProfileController extends Zend_Controller_Action {
    //Phuong thuc init()
    public function init() {
        $app = Zend_Registry::get('App');
        $this->view->baseUrl = $baseUrl = $this->_request->getBaseUrl() . "/public/";
        $result = array(
                    array($baseUrl.'lib-js/system/admin/System_Admin_Profile.js','js')
                    ,array($baseUrl.'lib-js/jquery.md5.js','js')
                    ,array($baseUrl.'lib-js/jquery.lightbox_me.js','js')
                    ,array($baseUrl.'lib-js/ui/jquery.ui.datepicker-vi.js','js')
                    ,array($baseUrl.'css/popup.css','css')
                    ,array($baseUrl.'css/user.css','css')
                    ,array($baseUrl.'css/themes/blitzer/jquery-ui-1.8.14.custom.css','css')
                    ,array($baseUrl.'css/themes/base/calendar.css','css')
                );
        if ($this->_request->isXmlHttpRequest()){
            Zend_Layout::startMvc(array(
                'layoutPath' => $app->layout,
                'layout' => 'partial'
            ));
            $this->view->arrJsCss = Zend_Json::encode($result);
        }else{
            //Cau hinh cho Zend_layout
            Zend_Layout::startMvc(array(
                'layoutPath' => $app->layout,
                'layout' => 'index'
            ));
            $response = $this->getResponse();
            
            $this->view->currentModulCode = "profile";
            $this->view->currentModulCodeForLeft = "index";
            $this->view->postHeader = Clound_String::registerFile($result);

            //Hien thi file template
            $response->insert('menu', $this->view->renderLayout('menu.phtml', './application/layout/scripts/'));     //Hien thi header 
            $response->insert('submenu', $this->view->renderLayout('submenu.phtml', './application/layout/scripts/'));     //Hien thi header 
            $response->insert('footer', $this->view->renderLayout('footer.phtml', './application/layout/scripts/'));   //Hien thi f
        }

    }

    public function indexAction() {
        $model = new system_models_Staff();
        $currentStaff = Zend_Auth::getInstance()->getIdentity();
        $id = $currentStaff->StaffID;
        $model = $model->selectRow($id, '', '');
        $this->view->model = $model;

    }
    public function saveinfoAction() {
        $model = new system_models_Staff();
        $currentStaff = Zend_Auth::getInstance()->getIdentity();
        $id = $currentStaff->StaffID;
        $Birthday   = Clound_Datetime::getInstance()->convertDateTime($this->_request->getParam('Birthday'));
        $data = array(
                "Sex"       => $this->_request->getParam('Sex'),
                "Address"   => $this->_request->getParam('Adress'),
                "Birthday"  => $Birthday,
                "Mobile"    => $this->_request->getParam('Mobile'),
                "Email"     => $this->_request->getParam('Email'),
            );
        echo $model->update($data,"StaffID ='$id'");
        die;
    }
    public function changepassAction() {
        $model = new system_models_Staff();
        $currentStaff = Zend_Auth::getInstance()->getIdentity();
        $id = $currentStaff->StaffID;
        $passOld = $this->_request->getParam('passOld');
        $passNew = $this->_request->getParam('passNew');
        $data = array('Password' => $passNew);
        $result = $model->update($data,"StaffID ='$id' And Password ='$passOld'");
        echo $result;
        die;
    }
}
?>